package org.jeecg.modules.health_code.controller;

import cn.hutool.crypto.SmUtil;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Hex;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.bouncycastle.util.encoders.Base64;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.SM2Utils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.health_code.entity.HealthCode;
import org.jeecg.modules.health_code.entity.request.ApiCommonRequest;
import org.jeecg.modules.health_code.entity.request.ApiTokenRequest;
import org.jeecg.modules.health_code.entity.request.bo.*;
import org.jeecg.modules.health_code.entity.response.*;
import org.jeecg.modules.health_code.entity.response.bo.AccessOrgResponse;
import org.jeecg.modules.health_code.entity.response.bo.RegqueryResponse;
import org.jeecg.modules.health_code.entity.response.bo.TokenResponse;
import org.jeecg.modules.health_code.entity.response.bo.UseCardResponse;
import org.jeecg.modules.health_code.service.IHealthCodeService;
import org.jeecg.modules.nurse_user.entity.NurseUser;
import org.jeecg.modules.nurse_user.service.INurseUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.security.PublicKey;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 电子健康码
 * @Author: jeecg-boot
 * @Date:   2025-07-07
 * @Version: V1.0
 */
@Api(tags="电子健康码")
@RestController
@RequestMapping("/health_code/healthCode")
@Slf4j
public class HealthCodeController extends JeecgController<HealthCode, IHealthCodeService> {
	@Autowired
	private IHealthCodeService healthCodeService;

	@Autowired
	private INurseUserService nurseUserService;

	@Autowired
	private RedisUtil redisUtil;

	@Value("${healthcode.nurse.encType:}")
	private String encType;

	@Value("${healthcode.nurse.digestType:}")
	private String digestType;

	@Value("${healthcode.nurse.version:}")
	private String version;

	@Value("${healthcode.nurse.appId:}")
	private String appId;

	@Value("${healthcode.nurse.secret:}")
	private String secret;

	@Value("${healthcode.nurse.appMode:}")
	private String appMode;

	@Value("${healthcode.nurse.publicKeyBase64:}")
	private String publicKeyBase64;

	@Value("${healthcode.nurse.klx:}")
	private String klx;



	
	/**
	 * 分页列表查询
	 *
	 * @param healthCode
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "电子健康码-分页列表查询")
	@ApiOperation(value="电子健康码-分页列表查询", notes="电子健康码-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<HealthCode>> queryPageList(HealthCode healthCode,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<HealthCode> queryWrapper = QueryGenerator.initQueryWrapper(healthCode, req.getParameterMap());
		Page<HealthCode> page = new Page<HealthCode>(pageNo, pageSize);
		IPage<HealthCode> pageList = healthCodeService.page(page, queryWrapper);
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param healthCode
	 * @return
	 */
	@AutoLog(value = "电子健康码-添加")
	@ApiOperation(value="电子健康码-添加", notes="电子健康码-添加")
	@RequiresPermissions("health_code:health_code:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody HealthCode healthCode) {
		healthCodeService.save(healthCode);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param healthCode
	 * @return
	 */
	@AutoLog(value = "电子健康码-编辑")
	@ApiOperation(value="电子健康码-编辑", notes="电子健康码-编辑")
	@RequiresPermissions("health_code:health_code:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody HealthCode healthCode) {
		healthCodeService.updateById(healthCode);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "电子健康码-通过id删除")
	@ApiOperation(value="电子健康码-通过id删除", notes="电子健康码-通过id删除")
	@RequiresPermissions("health_code:health_code:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		healthCodeService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "电子健康码-批量删除")
	@ApiOperation(value="电子健康码-批量删除", notes="电子健康码-批量删除")
	@RequiresPermissions("health_code:health_code:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.healthCodeService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "电子健康码-通过id查询")
	@ApiOperation(value="电子健康码-通过id查询", notes="电子健康码-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<HealthCode> queryById(@RequestParam(name="id",required=true) String id) {
		HealthCode healthCode = healthCodeService.getById(id);
		if(healthCode==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(healthCode);
	}


	 @PostMapping("getToken")
	 @AutoLog(value = "健康码-获取访问令牌")
	 @ApiOperation(value = "健康码-获取访问令牌", notes = "健康码-获取访问令牌")
	 @ResponseBody
	 public Result<?> getToken() {
		 JSONObject jsonObject=null;
		 String result;
		 String access_token;
		 String url;
		 try {

			 ApiTokenRequest apiTokenRequest = new ApiTokenRequest();
			 apiTokenRequest.setAppId(appId);
			 apiTokenRequest.setDigestType(digestType);
			 apiTokenRequest.setMethod("token");
			 apiTokenRequest.setTimestamp(String.valueOf(System.currentTimeMillis()));
			 apiTokenRequest.setVersion(version);
			 apiTokenRequest.setDigestType("SM2");
			 apiTokenRequest.setEncType("SM4");


			 //加密token,SM2
			 PublicKey restoredPublicKey = SM2Utils.base64ToPublicKey(publicKeyBase64);
			 String encrypted = SM2Utils.encrypt(secret, restoredPublicKey);
			 Base64.decode(encrypted);
			 String encryptToken = Hex.encodeHexString(Base64.decode(encrypted)).toUpperCase(); // 转十六进制（大写）

			 // SM2 sm2 = SmUtil.sm2(null, publicKeyBase64);
			 // String encryptToken = sm2.encryptBcd(secret, KeyType.PublicKey);

			 TokenRequest tokenRequest = new TokenRequest();
			 tokenRequest.setSecret(encryptToken);
			 apiTokenRequest.setBizContent(tokenRequest);


			 String rs = HttpRequest.post("https://ecard.wjw.gz.gov.cn:9595/internet/api/app/v1/token")
					 .header("appCode", "AcDIkr")//头信息，多个头信息多次调用此方法即可
					 .header("sign", "B3570518FC7E1CD9E630CDC03567E565")//头信息，多个头信息多次调用此方法即可
					 .body(JSONUtil.toJsonStr(apiTokenRequest))//表单内容
					 .timeout(10000)//超时，毫秒
					 .execute().body();
			 System.out.println(rs);
			 if (JSONUtil.isJson(rs)) {
				 JSONObject jSONObject = JSONUtil.parseObj(rs, true);
				 if (jSONObject.getStr("respCode").equals("10000")) {
					 ApiCommonResponse apiCommonResponse =
							 JSONUtil.toBean(jSONObject.getJSONObject("respData"), ApiCommonResponse.class);
					 ApiTokenResponse apiTokenResponse = new ApiTokenResponse();
					 apiTokenResponse.setNetConsumeTime(apiCommonResponse.getNetConsumeTime());
					 apiTokenResponse.setBusConsumeTime(apiCommonResponse.getBusConsumeTime());
					 apiTokenResponse.setThirdPartyTime(apiCommonResponse.getThirdPartyTime());
					 apiTokenResponse.setExt(apiCommonResponse.getExt());
					 TokenResponse tokenResponse = JSONUtil.toBean(apiCommonResponse.getBizContent(), TokenResponse.class);
					 apiTokenResponse.setBizContent(tokenResponse);
					 redisUtil.set("hc_access_token", tokenResponse.getToken(), 7000);
					 return Result.ok(apiTokenResponse);
				 } else {
					 return Result.error(jSONObject.getStr("respDesc"));
				 }
			 }
		 }
		 catch (Exception e) {
			 log.error(e.getMessage(), e);
		 }

		 return Result.error(jsonObject.getStr("respDesc"));
	 }




	 @PostMapping("getRegquery")
	 @AutoLog(value = "健康码-电子健康卡用户注册或查询")
	 @ApiOperation(value = "健康码-电子健康卡用户注册或查询", notes = "健康码-电子健康卡用户注册或查询")
	 @ResponseBody
	 public Result<?> getRegquery(
			 @RequestBody RegqueryRequest regqueryRequest
			 ) {
		 JSONObject jsonObject=null;
		 Map<String, String> params = new HashMap<>();
		 String result;
		 String access_token;
		 String url;
		 CloseableHttpClient httpClient = null;
		 CloseableHttpResponse httpResponse = null;
		 try {

			 if (redisUtil.hasKey("hc_access_token")) {
				 access_token = redisUtil.get("hc_access_token").toString();
			 }
			 else {
				 return Result.error("获取不到token!!");
			 }

			 ApiCommonRequest apiCommonRequest = new ApiCommonRequest();
			 apiCommonRequest.setAppId(appId);
			 apiCommonRequest.setDigestType(digestType);
			 apiCommonRequest.setEncType(encType);
			 apiCommonRequest.setMethod( "regquery");
			 apiCommonRequest.setTimestamp(String.valueOf(System.currentTimeMillis()));
			 apiCommonRequest.setVersion(version);


			 //加密token,SM2
			 PublicKey restoredPublicKey = SM2Utils.base64ToPublicKey(publicKeyBase64);
			 String encrypted = SM2Utils.encrypt(access_token, restoredPublicKey);
			 Base64.decode(encrypted);
			 String encryptToken = Hex.encodeHexString(Base64.decode(encrypted)).toUpperCase(); // 转十六进制（大写）

			 //加密token,SM2
			// SM2 sm2 = SmUtil.sm2(null, publicKeyBase64);
			// String encryptToken = sm2.encryptBcd(access_token, KeyType.PublicKey);
			 apiCommonRequest.setDigest(encryptToken);

			 //加密内容,SM4
			 String contentStr = JSONUtil.toJsonStr(regqueryRequest);
			 SymmetricCrypto sm4 = SmUtil.sm4(access_token.getBytes());
			 apiCommonRequest.setBizContent(sm4.encryptHex(contentStr));
			 System.out.println(JSONUtil.toJsonStr(apiCommonRequest));
			 String rs = HttpRequest.post("https://ecard.wjw.gz.gov.cn:9595/internet/api/app/v1/ecard")
					// .header("appCode", "AcDIkr")//头信息，多个头信息多次调用此方法即可
					 //.header("sign", "B3570518FC7E1CD9E630CDC03567E565")//头信息，多个头信息多次调用此方法即可
					 .body(JSONUtil.toJsonStr(apiCommonRequest))//表单内容
					 .timeout(10000)//超时，毫秒
					 .execute().body();
			 System.out.println(rs);
			 if (JSONUtil.isJson(rs))
			 {
				 JSONObject jSONObject = JSONUtil.parseObj(rs, true);
				 if (jSONObject.getStr("respCode").equals("10000"))
				 {
					 ApiCommonResponse apiCommonResponse =
							 JSONUtil.toBean(jSONObject.getJSONObject("respData"), ApiCommonResponse.class);
					 String encryptRst = apiCommonResponse.getBizContent();
					 //解密
					 String contentRst = sm4.decryptStr(encryptRst);

					 ApiRegqueryResponse apiregqueryResponse = new ApiRegqueryResponse();
					 apiregqueryResponse.setNetConsumeTime(apiCommonResponse.getNetConsumeTime());
					 apiregqueryResponse.setBusConsumeTime(apiCommonResponse.getBusConsumeTime());
					 apiregqueryResponse.setThirdPartyTime(apiCommonResponse.getThirdPartyTime());
					 apiregqueryResponse.setExt(apiCommonResponse.getExt());
					 RegqueryResponse regqueryResponse = JSONUtil.toBean(contentRst, RegqueryResponse.class);
					 apiregqueryResponse.setBizContent(regqueryResponse);

					 NurseUser nurseUser = nurseUserService.getOne(new QueryWrapper<NurseUser>().eq("openid", regqueryRequest.getOpenid()));
					 if (oConvertUtils.isNotEmpty(nurseUser)) {
						 nurseUser.setVuid(regqueryResponse.getVuid());
						 nurseUserService.updateById(nurseUser);
					 }

					 return Result.ok(apiregqueryResponse);
				 }
				 else {
					 return Result.error(jSONObject.getStr("respDesc"));
				 }
			 }
		 }
			  catch (Exception e) {
				 log.error(e.getMessage(), e);
			 }

		 return Result.error(jsonObject.getStr("respDesc"));
	}

	@PostMapping("getApply")
	@AutoLog(value = "健康码-获取电子健康卡二维码图片")
	@ApiOperation(value = "健康码-获取电子健康卡二维码图片", notes = "健康码-获取电子健康卡二维码图片")
	@ResponseBody
	public Result<?> getApply(
			@RequestBody ApplyRequest applyRequest
	) {
		JSONObject jsonObject=null;
		Map<String, String> params = new HashMap<>();
		String result;
		String access_token;
		String url;
		CloseableHttpClient httpClient = null;
		CloseableHttpResponse httpResponse = null;
		try {

			if (redisUtil.hasKey("hc_access_token")) {
				access_token = redisUtil.get("hc_access_token").toString();
			}
			else {
				return Result.error("获取不到token!!");
			}

			ApiCommonRequest apiCommonRequest = new ApiCommonRequest();
			apiCommonRequest.setAppId(appId);
			apiCommonRequest.setDigestType(digestType);
			apiCommonRequest.setEncType(encType);
			apiCommonRequest.setMethod( "apply");
			apiCommonRequest.setTimestamp(String.valueOf(System.currentTimeMillis()));
			apiCommonRequest.setVersion(version);


			//加密token,SM2
			PublicKey restoredPublicKey = SM2Utils.base64ToPublicKey(publicKeyBase64);
			String encrypted = SM2Utils.encrypt(access_token, restoredPublicKey);
			Base64.decode(encrypted);
			String encryptToken = Hex.encodeHexString(Base64.decode(encrypted)).toUpperCase(); // 转十六进制（大写）
			apiCommonRequest.setDigest(encryptToken);

			//ApplyRequest applyRequest=new ApplyRequest();
			//applyRequest.setVuid("EA22E3C84A5BB270BEB6A4D4UY2532AFB09F3F09DA80651774A1BD29EB181B5E");

			//加密内容,SM4
			String contentStr = JSONUtil.toJsonStr(applyRequest);
			SymmetricCrypto sm4 = SmUtil.sm4(access_token.getBytes());
			apiCommonRequest.setBizContent(sm4.encryptHex(contentStr));
			System.out.println(JSONUtil.toJsonStr(apiCommonRequest));
			String rs = HttpRequest.post("https://ecard.wjw.gz.gov.cn:9595/internet/api/app/v1/ecard")
					.body(JSONUtil.toJsonStr(apiCommonRequest))//表单内容
					.timeout(10000)//超时，毫秒
					.execute().body();
			System.out.println(rs);
			if (JSONUtil.isJson(rs))
			{
				JSONObject jSONObject = JSONUtil.parseObj(rs, true);
				if (jSONObject.getStr("respCode").equals("10000"))
				{
					ApiCommonResponse apiCommonResponse =
							JSONUtil.toBean(jSONObject.getJSONObject("respData"), ApiCommonResponse.class);
					String encryptRst = apiCommonResponse.getBizContent();
					//解密
					String contentRst = sm4.decryptStr(encryptRst);

					ApiRegqueryResponse apiregqueryResponse = new ApiRegqueryResponse();
					apiregqueryResponse.setNetConsumeTime(apiCommonResponse.getNetConsumeTime());
					apiregqueryResponse.setBusConsumeTime(apiCommonResponse.getBusConsumeTime());
					apiregqueryResponse.setThirdPartyTime(apiCommonResponse.getThirdPartyTime());
					apiregqueryResponse.setExt(apiCommonResponse.getExt());
					RegqueryResponse regqueryResponse = JSONUtil.toBean(contentRst, RegqueryResponse.class);
					apiregqueryResponse.setBizContent(regqueryResponse);
					return Result.ok(apiregqueryResponse);
				}
				else {
					return Result.error(jSONObject.getStr("respDesc"));
				}
			}
		}
		catch (Exception e) {
			log.error(e.getMessage(), e);
		}
		return Result.error(jsonObject.getStr("respDesc"));
	}

	@PostMapping("accessOrg")
	@AutoLog(value = "健康码-接入机构查询")
	@ApiOperation(value = "健康码-接入机构查询", notes = "健康码-接入机构查询")
	@ResponseBody
	public Result<?> accessOrg(
			//@RequestBody AccessOrgRequest accessOrgRequest
	) {
		JSONObject jsonObject=null;
		Map<String, String> params = new HashMap<>();
		String result;
		String access_token;
		String url;
		CloseableHttpClient httpClient = null;
		CloseableHttpResponse httpResponse = null;
		try {

			if (redisUtil.hasKey("hc_access_token")) {
				access_token = redisUtil.get("hc_access_token").toString();
			}
			else {
				return Result.error("获取不到token!!");
			}

			ApiCommonRequest apiCommonRequest = new ApiCommonRequest();
			apiCommonRequest.setAppId(appId);
			apiCommonRequest.setDigestType(digestType);
			apiCommonRequest.setEncType(encType);
			apiCommonRequest.setMethod( "accessOrgs");
			apiCommonRequest.setTimestamp(String.valueOf(System.currentTimeMillis()));
			apiCommonRequest.setVersion(version);


			//加密token,SM2
			PublicKey restoredPublicKey = SM2Utils.base64ToPublicKey(publicKeyBase64);
			String encrypted = SM2Utils.encrypt(access_token, restoredPublicKey);
			Base64.decode(encrypted);
			String encryptToken = Hex.encodeHexString(Base64.decode(encrypted)).toUpperCase(); // 转十六进制（大写）
			apiCommonRequest.setDigest(encryptToken);

			//ApplyRequest applyRequest=new ApplyRequest();
			//applyRequest.setVuid("EA22E3C84A5BB270BEB6A4D4UY2532AFB09F3F09DA80651774A1BD29EB181B5E");
			AccessOrgRequest accessOrgRequest=new AccessOrgRequest();
			accessOrgRequest.setTypeCode("C");
			//加密内容,SM4
			String contentStr = JSONUtil.toJsonStr(accessOrgRequest);
			SymmetricCrypto sm4 = SmUtil.sm4(access_token.getBytes());
			apiCommonRequest.setBizContent(sm4.encryptHex(contentStr));
			System.out.println(JSONUtil.toJsonStr(apiCommonRequest));
			String rs = HttpRequest.post("https://ecard.wjw.gz.gov.cn:9595/internet/api/app/v1/ecard")
					.body(JSONUtil.toJsonStr(apiCommonRequest))//表单内容
					.timeout(10000)//超时，毫秒
					.execute().body();
			System.out.println(rs);
			if (JSONUtil.isJson(rs))
			{
				JSONObject jSONObject = JSONUtil.parseObj(rs, true);
				if (jSONObject.getStr("respCode").equals("10000"))
				{
					ApiCommonResponse apiCommonResponse =
							JSONUtil.toBean(jSONObject.getJSONObject("respData"), ApiCommonResponse.class);
					String encryptRst = apiCommonResponse.getBizContent();
					//解密
					String contentRst = sm4.decryptStr(encryptRst);
					ApiAccessOrgResponse apiAccessOrgResponse = new ApiAccessOrgResponse();
					apiAccessOrgResponse.setNetConsumeTime(apiCommonResponse.getNetConsumeTime());
					apiAccessOrgResponse.setBusConsumeTime(apiCommonResponse.getBusConsumeTime());
					apiAccessOrgResponse.setThirdPartyTime(apiCommonResponse.getThirdPartyTime());
					apiAccessOrgResponse.setExt(apiCommonResponse.getExt());
					List<AccessOrgResponse> accessOrgResponse = JSONUtil.toList(contentRst, AccessOrgResponse.class);
					apiAccessOrgResponse.setBizContent(accessOrgResponse);
					return Result.ok(apiAccessOrgResponse);
				}
				else {
					return Result.error(jSONObject.getStr("respDesc"));
				}
			}
		}
		catch (Exception e) {
			log.error(e.getMessage(), e);
		}
		return Result.error(jsonObject.getStr("respDesc"));
	}

	@PostMapping("useCardLog")
	@AutoLog(value = "健康码-用卡记录")
	@ApiOperation(value = "健康码-用卡记录", notes = "健康码-用卡记录")
	@ResponseBody
	public Result<?> useCardLog(
		//	@RequestBody UseCardRequest useCardRequest
	) {
		JSONObject jsonObject=null;
		Map<String, String> params = new HashMap<>();
		String result;
		String access_token;
		String url;
		CloseableHttpClient httpClient = null;
		CloseableHttpResponse httpResponse = null;
		try {

			if (redisUtil.hasKey("hc_access_token")) {
				access_token = redisUtil.get("hc_access_token").toString();
			}
			else {
				return Result.error("获取不到token!!");
			}

			ApiCommonRequest apiCommonRequest = new ApiCommonRequest();
			apiCommonRequest.setAppId(appId);
			apiCommonRequest.setDigestType(digestType);
			apiCommonRequest.setEncType(encType);
			apiCommonRequest.setMethod( "useCardLog");
			apiCommonRequest.setTimestamp(String.valueOf(System.currentTimeMillis()));
			apiCommonRequest.setVersion(version);


			//加密token,SM2
			PublicKey restoredPublicKey = SM2Utils.base64ToPublicKey(publicKeyBase64);
			String encrypted = SM2Utils.encrypt(access_token, restoredPublicKey);
			Base64.decode(encrypted);
			String encryptToken = Hex.encodeHexString(Base64.decode(encrypted)).toUpperCase(); // 转十六进制（大写）
			apiCommonRequest.setDigest(encryptToken);

			//ApplyRequest applyRequest=new ApplyRequest();
			//applyRequest.setVuid("EA22E3C84A5BB270BEB6A4D4UY2532AFB09F3F09DA80651774A1BD29EB181B5E");
			UseCardRequest useCardRequest=new UseCardRequest();
			//黎
			//useCardRequest.setVuid("EA22E3C84A5BB270BEB6A4D4UY2532AFB09F3F09DA80651774A1BD29EB181B5E");
			//李
			useCardRequest.setVuid("788664428CC1B93A5ED724337D8404CE7F534698BA88728DBBC75A1295129CA3");

			//加密内容,SM4
			String contentStr = JSONUtil.toJsonStr(useCardRequest);
			SymmetricCrypto sm4 = SmUtil.sm4(access_token.getBytes());
			apiCommonRequest.setBizContent(sm4.encryptHex(contentStr));
			System.out.println(JSONUtil.toJsonStr(apiCommonRequest));
			String rs = HttpRequest.post("https://ecard.wjw.gz.gov.cn:9595/internet/api/app/v1/ecard")
					.body(JSONUtil.toJsonStr(apiCommonRequest))//表单内容
					.timeout(10000)//超时，毫秒
					.execute().body();
			System.out.println(rs);
			if (JSONUtil.isJson(rs))
			{
				JSONObject jSONObject = JSONUtil.parseObj(rs, true);
				if (jSONObject.getStr("respCode").equals("10000"))
				{
					ApiCommonResponse apiCommonResponse =
							JSONUtil.toBean(jSONObject.getJSONObject("respData"), ApiCommonResponse.class);
					String encryptRst = apiCommonResponse.getBizContent();
					//解密
					String contentRst = sm4.decryptStr(encryptRst);
					ApiUseCardResponse apiUseCardResponse = new ApiUseCardResponse();
					apiUseCardResponse.setNetConsumeTime(apiCommonResponse.getNetConsumeTime());
					apiUseCardResponse.setBusConsumeTime(apiCommonResponse.getBusConsumeTime());
					apiUseCardResponse.setThirdPartyTime(apiCommonResponse.getThirdPartyTime());
					apiUseCardResponse.setExt(apiCommonResponse.getExt());
					List<UseCardResponse> useCardResponse = JSONUtil.toList(contentRst, UseCardResponse.class);
					apiUseCardResponse.setBizContent(useCardResponse);
					return Result.ok(apiUseCardResponse);
				}
				else {
					return Result.error(jSONObject.getStr("respDesc"));
				}
			}
		}
		catch (Exception e) {
			log.error(e.getMessage(), e);
		}
		return Result.error(jsonObject.getStr("respDesc"));
	}

}
